package com.car.carmgr.service.impl;

import com.car.carmgr.bean.LogInfo;
import com.car.carmgr.mapper.LogInfoMapper;
import com.car.carmgr.service.LogInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LogInfoServiceImpl implements LogInfoService {

    @Autowired
    private LogInfoMapper logInfoMapper;

    @Override
    public int insertLogInfo(LogInfo logInfo) {
        return logInfoMapper.insertLogInfo(logInfo);
    }

    @Override
    public int deleteLogInfoById(Integer logInfoId) {
        return logInfoMapper.deleteLogInfoById(logInfoId);
    }

    @Override
    public int updateLogInfo(LogInfo logInfo) {
        return logInfoMapper.updateLogInfo(logInfo);
    }

    @Override
    public PageInfo<LogInfo> findLogInfoByWhere(LogInfo logInfo, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<LogInfo> list = logInfoMapper.findLogInfoByWhere(logInfo);
        PageInfo<LogInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer getCountByWhere(LogInfo logInfo) {
        return logInfoMapper.getCountByWhere(logInfo);
    }

    @Override
    public int deleteSomeLogInfo(String[] split) {
        int row = 0;
        if(split != null && split.length != 0){

            for(String id : split){
                row += logInfoMapper.deleteLogInfoById(Integer.parseInt(id));
            }
        }
        return row;
    }
}
